<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
		<title>订单支付</title>
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/base.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/mod.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/list.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/page.css" />
		<link rel="stylesheet" type="text/css" media="screen" href="{$staticHost}/static/css/competition.css?v=1" />
		<script src="{$staticHost}/static/js/jquery-1.8.3.min.js"></script>
		<script src="{$staticHost}/static/js/js.js"></script>
		<script src="{$staticHost}/static/js/mod.js"></script>
		<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
	</head>
	<body class="bg_gray_light pb50">
		<div id="pay-box"></div>

		<script type="text/html" id="pay">
			<div class="bg_skyblue ac f14 color-blue bold p10">
				请在 <%=result.orderInfo.expireTime%> 之前完成付款
			</div>
			<div class="recipients bg_wirte">
				<%=result.orderInfo.name%> <span class="pl20"><%=result.orderInfo.phone%></span>
				<%if(result.orderInfo.goodsList==1){%><%}%>
				<p><%=result.orderInfo.address%></p>
				
			</div>
			<div class="p10 lh30 f14 color_gray bg_wirte mt20">
				订单号码　<%=result.orderInfo.order_id%><br/>
				创建时间　<%=result.orderInfo.addtime%><br/>
			</div>
			<p class="p10 bg_gray_light color_gray f14"> 选择支付方式</p>
			
			<ul class="apply-list bg_wirte">
				<% for(var i=0; i<result.paymentList.length; i++){%>
				<li>
					<%if(result.paymentList[i].payment_type==2){%>
						<img src="{$staticHost}/static/images/share/zfb.png">
					<%}%>
					<%if(result.paymentList[i].payment_type==12){%>
						<img src="{$staticHost}/static/images/share/wx.png">
					<%}%>
					<%=result.paymentList[i].title%>
					<input class="fs" type="radio" name="way" checked="checked" value="<%=result.paymentList[i].payment_type%>" />
				</li>
				<%}%>
			</ul>
			<div class="btn-apply pa">
				合计：<span class="color-blue">￥<%=result.orderInfo.total_fee%></span>
				<a id="submit" class="red">提交订单</a>
			</div>
		</script>
	</body>
	<script>
		var order_id ='{$order_id}';
		var match_id;
		$(function(){
			$.getJSON('{$staticHost}/orderWeb/orderDetail',{'order_id':order_id}, function(data, error) {
				var info=data.result.orderInfo;
				var status = info.status;

				match_id =(info.match_id)*1;
				var q = new Date(parseInt(info.expireTime) * 1000);
				info.expireTime=xs(q.getMonth()+1)+"."+xs(q.getDate())+ " "+xs(q.getHours())+":"+xs(q.getMinutes());
				function xs(n){ return n<10?("0"+n):n;}


				var html = template('pay', data);
				document.getElementById('pay-box').innerHTML = html;
				var payment_type = $(".fs").val()
				if(info.status==2){
					$("#submit").css("background","#ADADB3");
					return;
				}
				$("#submit").click(function(){
					
					var payment_type = $(".fs").val();
                    $.getJSON('{$staticHost}/orderWeb/pay',{order_id:order_id,payment_type:payment_type},function(data){
                        if(data.status && data.status.code == 200){
                            goPay(data.result,match_id)
                        }
                    })
                     $("#submit").css("background","#ADADB3");
                     $("#submit").unbind();
				})


				
			})
			/***加载数据***/
		});
		 function goPay(data,match_id){
	        if(data.payment_type=='12'){
	          //微信公众号
	          /*
	          wx.config({
	            debug: true,
	            appId: 'wx6e9f935be224ef2e',
	            timestamp: 1473755127,
	            nonceStr: 'TbtQj7BRG3z3M2aM',
	            signature: '091de08a6d641fec9b10148ae86443fb98a382cf',
	            jsApiList: [
	              'chooseWXPay'
	            ]
	          });
	          */
	          wx.config(data.pay_str.wx_config)
	          wx.ready(function () {

	            //data.pay_str.wx_pay_params.paySign = data.pay_str.wx_pay_params.sign
	            var params = data.pay_str.wx_pay_params
	            wx.chooseWXPay({
	                timestamp: params.timeStamp,
	                nonceStr: params.nonceStr, 
	                package: params.package,
	                signType: params.signType, 
	                paySign: params.sign,
	                success: function (res) {
	                     alert("支付成功");
	                    if(match_id){
	                     location.href = 'http://irun.hupu.com/show/matchInfo?match_id='+match_id;
	                    }else{
	                        alert("支付成功")
	                    }
	                }
	            });
	          });
	        }else{
	            //支付宝
	            window.location.href = data.pay_host + '?' + data.pay_str
	        }
	    }
	// 支付

	</script>
{template 'show/web-footer'}
